﻿using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Text;

public partial class _Contacts : System.Web.UI.Page 
{
    protected LocalFunctions FUNC;

    protected void Page_Load(object sender, EventArgs e)
    {
        FUNC = ((Rondo)Master).FUNC;
        if (FUNC.LangID == 2)
            tblMain.Attributes.Add("dir", "rtl");

        HtmlLink css1 = new HtmlLink();
        css1.Href = (FUNC.LangID == 1) ? "style/basic.css" : "style/basicHeb.css";
        css1.Attributes["rel"] = "stylesheet";
        css1.Attributes["type"] = "text/css";
        css1.Attributes["media"] = "screen";
        Page.Header.Controls.Add(css1);

        wmName.WatermarkText=FUNC.GetPhrase(26);
        wmLastName.WatermarkText = FUNC.GetPhrase(27);
        wmEmail.WatermarkText = FUNC.GetPhrase(28);
        wmPhone.WatermarkText = FUNC.GetPhrase(29);
        wmContent.WatermarkText=FUNC.GetPhrase(30);

        btnSend.Text = FUNC.GetPhrase(31);

        Dal.arParams.Clear();
        Dal.arParams.Add(6); //Pagetype contacts
        Dal.arParams.Add(FUNC.LangID);
        DataTable DT = Dal.ExecuteDBsp("RD_SelectStaticPageById", Dal.arParams);
        
        if (DT != null)
        {
            if (DT.Rows.Count > 0)
            {
                Title = DT.Rows[0]["PageTitle"].ToString();
                PageContent.InnerHtml = DT.Rows[0]["PageContent"].ToString();
                imgTitle.Src = FUNC.FullAppPath + "/Gallery/" + DT.Rows[0]["imageLink"].ToString();
            }
        }
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        string sToEmail = Dal.ExecuteDBspOneValue("Admin_GetEmail", null).ToString();
        StringBuilder sb = new StringBuilder();

        if (FUNC.LangID == 1)
        {
            sb.Append("Здравствуйте, Анна!<br />");
            sb.AppendFormat("{0} {1} ({2}) , номер телефона: {3} хочет вам сообщить:<br />", txtName.Text, txtLastName.Text, txtEmail.Text, txtPhone.Text);
            sb.Append(txtContent.Text);
        }
        else
        {
            sb.Append("שלום, אנה!<br />");
            sb.AppendFormat("{0} {1} ({2}) , ,מס טלפון: {3} רוצה להודיע לך:<br />", txtName.Text, txtLastName.Text, txtEmail.Text, txtPhone.Text);
            sb.Append(txtContent.Text);
        }
        //SendMail
        Helper.SendEmail(txtEmail.Text, txtName.Text, sToEmail, "Вы получили новое сообщение на сайт Rondo Dance.",sb);

        string message = string.Empty;
        if (FUNC.LangID == 1)
        {
            message = "Ваше сообщение отправлено!";
        }
        else
        {
            message = "ההודעה שלך נשלחה בהצלחה!";
        }
        MyMessageBoxInfo.Show(MyMessageBox.MessageType.Info, message, 125, 300);

        txtContent.Text = string.Empty;
        txtEmail.Text= string.Empty;
        txtLastName.Text = string.Empty;
        txtName.Text = string.Empty;
        txtPhone.Text = string.Empty;
    }
}
